package org.agony2d.gpu {
	import flash.utils.ByteArray;
	import org.agony2d.debug.Logger;
	import org.agony2d.gpu.core.GroupAA;
	import org.agony2d.core.agony_internal;
	import org.agony2d.gpu.core.NodeAA;
	import org.agony2d.gpu.core.VertexConvergence;
	
	use namespace agony_internal;
	
	/**  */
	/** [ BatchGroupAA ]
	 *  [◆]
	 *  	1.  reset
	 *  [★]
	 *  	a.  批处理型GroupAA，子NodeAA不可包含GroupAA，可手动更新(使用◆reset)...
	 */
public class BatchGroupAA extends AloneGroupAA {
	
    public function BatchGroupAA( fullTextureName:String, tinted:Boolean = false, smoothing:Boolean = false ) {
		super(fullTextureName, tinted, smoothing)
		m_bytes = new ByteArray
		m_needBatchUpdate = true
    }
	
	public function reset() : void {
		m_needBatchUpdate = true
	}
	
	override agony_internal function doValidateNode( node:NodeAA ) : void {
		if (node is GroupAA) {
			Logger.reportError(this, "doValidateNode", "Added node can't be GroupAA type...")
		}
		if (node.m_parent) {
			if (node.m_fullTexture != m_fullTexture) {
				Logger.reportError(this, "doValidateNode", "Full texture alters...!!")
			}
			node.m_parent.removeNode(node)
			node.m_altered = true
		}
		else {
			node.m_fullTexture = m_fullTexture
		}
		node.m_world = m_world
		node.m_parent = this
	}
	
	override agony_internal function render( vertexChanged:Boolean, tinted:Boolean ) : void {
		if (!m_program || m_numNodes <= 0 || m_invisible) {
			return
		}
		this.doFinishPrevGroup()
		if (m_needBatchUpdate) {
			this.doIntegrateVertex(vertexChanged, tinted)
			m_bytes.length = 0
			m_bytes.writeBytes(g_convergence.bytes)
			m_needBatchUpdate = false
		}
		else {
			g_convergence.bytes.writeBytes(m_bytes)
		}
		goFinishRender()
		this.doResumePrevGroup()
	}
	
	agony_internal var m_needBatchUpdate:Boolean
	agony_internal var m_bytes:ByteArray
}
}